package ezXpns.GUI.controllers;

import java.util.ArrayList;

import ezXpns.GUI.UndoableAction;


//@author A0086931X
public class UndoableBatch implements UndoableAction {
	
	public UndoableBatch(String name) {
		this.name = name;
	}

	public void add(UndoableAction action) {
		actions.add(action);
	}

	@Override
	public void execute() {
		//Execute in forward order
		for(int actionIndex = 0; actionIndex < actions.size(); ++actionIndex)
			actions.get(actionIndex).execute();
	}

	@Override
	public void undo() {
		//Execute in reverse order
		for(int actionIndex = actions.size() - 1; actionIndex >= 0; --actionIndex)
			actions.get(actionIndex).undo();	
	}

	private ArrayList<UndoableAction> actions = new ArrayList<UndoableAction>();

	@Override
	public String getName() {
		return name;
	}
	
	private String name;
}
